# 依赖注入：不明觉厉，感觉和 callback await .then 差不多的意思，但是感觉没那么嵌套 可以类型提示，自动解析和验证依赖项
# Depends 是 FastAPI 提供的

from typing import Annotated

from fastapi import Depends, FastAPI

app = FastAPI()


async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100):
    return {"q": q, "skip": skip, "limit": limit}

# 依赖可以作为类型复用
CommonsDep = Annotated[dict, Depends(common_parameters)]


@app.get("/items/")
async def read_items(commons: CommonsDep):
    return commons


@app.get("/users/")
async def read_users(commons: CommonsDep):
    return commons